package com.qsign.sfrz_android.utils;

import android.app.Activity;
import android.content.Context;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.XXPermissions;

import java.util.List;

/**
 * 请求权限工具
 */
public class PermissionsUtil {
      public  static void requestPersion(Activity activity,String[] persions){
          XXPermissions xxPermissions=XXPermissions.with(activity);
          // 可设置被拒绝后继续申请，直到用户授权或者永久拒绝
          xxPermissions.constantRequest();
           if(persions!=null){//不指定权限则自动获取清单中的危险权限
                xxPermissions.permission(persions);
            }
            xxPermissions.request(new OnPermission() {
              @Override
              public void hasPermission(List<String> granted, boolean isAll) {
              }
              @Override
              public void noPermission(List<String> denied, boolean quick) {
              }
          });
      }

    //判断是否有该权限 如果没有去设置  Permission.REQUEST_INSTALL_PACKAGES
    public static boolean havePersion(Activity activity,String[] persions){
        //Permission.REQUEST_INSTALL_PACKAGES
        if (XXPermissions.isHasPermission(activity,persions)){
            return true;
        }else{
            BaseUtil.ShowToast(activity,"此功能缺少必要权限，无法正常使用，请在设置中打开");
            XXPermissions.gotoPermissionSettings(activity);
            return false;
        }
    }

}
